//
//  FVDetailController.m
//  autoHome
//
//  Created by MS on 15/9/12.
//  Copyright (c) 2015年 qf1523. All rights reserved.
//

#import "FVDetailController.h"
#import "UMSocialSnsService.h"
#import "UMSocialDataService.h"
#import "UMSocialSnsPlatformManager.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialSinaHandler.h"
#import "UMSocialSinaSSOHandler.h"

#define UmengAppkey @"53290df956240b6b4a0084b3"
#define DTURL @"http://comm.app.api.autohome.com.cn/static/sharejump.html?p=1&pm=1&go=1&cont=4&ourl=http://forum.app.autohome.com.cn/autov4.8.8/forum/club/topicsharedcontent-t%@-o0.html"
@interface FVDetailController ()

@end

@implementation FVDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [UMSocialData setAppKey:UmengAppkey];
    
    //打开调试log的开关
    [UMSocialData openLog:YES];
    
//     [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQzone,UMShareToDouban,UMShareToRenren,UMShareToEmail,UMShareToSms,UMShareToFacebook,UMShareToTwitter]];
    //如果你要支持不同的屏幕方向，需要这样设置，否则在iPhone只支持一个竖屏方向
    [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskAll];
    
    //设置微信AppId，设置分享url，默认使用友盟的网址
    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
    
//    [UMSocial]
    //打开新浪微博的SSO开关
    [UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    [UMSocialSinaSSOHandler openNewSinaSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];

    [self creatUI];
  
    // Do any additional setup after loading the view.
}

//要返回源APP需要回调的函数
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return  [UMSocialSnsService handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url];
}

-(void)creatUI
{

    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:web];
      [self creatNavBar];
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:DTURL,self.dtId]]]];
    NSLog(@"%@",[NSString stringWithFormat:DTURL,self.dtId]);
    web.scrollView.bounces = NO;
    
    
}

-(void)creatNavBar
{
//    self.navigationController.navigationBarHidden = YES;
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
    headView.backgroundColor = [UIColor whiteColor];
    UIButton *lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lbtn.frame = CGRectMake(5, 20, 50, 30);
    [lbtn setImage:[UIImage imageNamed:@"bar_btn_icon_returntext@2x"] forState:UIControlStateNormal];
    [lbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    lbtn.backgroundColor = [UIColor redColor];
    [lbtn setTitle:@"返回" forState:UIControlStateNormal];
    [lbtn addTarget:self action:@selector(pressLBT:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:lbtn];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 63, self.view.frame.size.width, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [headView addSubview:line];
    line.alpha = 0.5;
    [self.view addSubview:headView];
    
    UIButton *rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rbtn.frame = CGRectMake(self.view.frame.size.width - 50, 20, 30, 30);
    
    [rbtn setImage:[UIImage imageNamed:@"btn_icon_share@2x"] forState:UIControlStateNormal];
    [rbtn addTarget:self action:@selector(pressRBT:) forControlEvents:UIControlEventTouchUpInside];
    
    [headView addSubview:rbtn];
}
-(void)pressRBT:(UIButton*)btn
{
    
    NSString *shareText = [NSString stringWithFormat:DTURL,self.dtId];             //分享内嵌文字
    UIImage *shareImage = [UIImage imageNamed:@"Icon-152.png"];          //分享内嵌图片
    
    NSLog(@"~~~~~~~%@",shareText);
    //调用快速分享接口
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:UmengAppkey
                                      shareText:shareText
                                     shareImage:shareImage
                                shareToSnsNames:[NSMutableArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ ,UMShareToQzone,UMShareToTencent,nil]
                                       delegate:self];
    

}
-(void)pressLBT:(UIButton*)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 自定义关闭授权页面事件
 
 @param navigationCtroller 关闭当前页面的navigationCtroller对象
 
 */
-(BOOL)closeOauthWebViewController:(UINavigationController *)navigationCtroller socialControllerService:(UMSocialControllerService *)socialControllerService
{
    return YES;
}

/**
 关闭当前页面之后
 
 @param fromViewControllerType 关闭的页面类型
 
 */
-(void)didCloseUIViewController:(UMSViewControllerType)fromViewControllerType
{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
